import request from "../utils/request";

const fileUrl='http://192.168.1.252/K3Cloud/FileUpLoadServices/download.aspx'
export function executeBillQuery(data){
    console.log('附件')
    return request({
        method:'POST',
        url:'/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc',
        data:data
    })
}

export function getFileUrl(file){
    file['token']=sessionStorage.getItem('userToken')
    window.open(fileUrl+'?fileId='+file.FFileId+'&token='+file.token)

}

export function upload2File(file){
    let userToken=sessionStorage.getItem('userToken')
    console.log(file)
    return request({
        method:'POST',
        url:"/FileUpLoadServices/FileService.svc/upload2attachment?filename="+file.name+"&token="+userToken
    })
}


export async function uploadFile(data){
    return request({
        method:'POST',
        url:'/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.AttachmentUpLoad.common.kdsvc',
        data:data    
    })
}

export function save(data){
    return request({
        method:'POST',
        url:'/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc',
        data:data
    })
}
export function batchSave(data){
    return request({
        method:'POST',
        url:'/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave.common.kdsvc',
        data:data
    })
}
export function deleteFile(data){
    return request({
        method:'POST',
        url:'/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete.common.kdsvc',
        data:data
    })
}

export function fileToBase64(file){
    let that =this,
    reader = new FileReader();
    reader.readAsDataURL(file);
    return new Promise((resolve,reject)=>{
        reader.onload = function (e) { //这里是一个异步，所以获取数据不好获取在实际项目中，就用new Promise解决
            if(this.result){
                resolve(this.result)
            }else{
                reject("err")
            }

        }
    })  
  }